package com.example.qxfw.dataBaseManager.Controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.YbzzForecaststation;
import com.example.qxfw.common.entity.qx.SmallScaleStation;
import com.example.qxfw.common.entity.qx.SpecialSrvStation;
import com.example.qxfw.common.entity.qx.TownshipStation;
import com.example.qxfw.common.entity.CountyPoint;
import com.example.qxfw.dataBaseManager.service.QxxxzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/6  星期四   16:34
 * @description : 此类用来 气象信息站
 ***************************************/
@Slf4j
@Api(tags = "数据库管理-气象信息站")
@RestController
@CrossOrigin
@RequestMapping("/QxxxzController")
public class QxxxzController {

    @Autowired
    private QxxxzService qxxxzService;

    @Value("${province}")
    private String m_province;

    @Value("${city}")
    private String m_city;

    @ApiOperation("区域自动站-初始化")
    @GetMapping("querySelect")
    public SysResult querySelect() {
        List<SmallScaleStation> smallScaleStations = this.qxxxzService.querySelect(m_province, m_city);
        return SysResult.success(smallScaleStations);
    }


    @ApiOperation("区域自动站-市更改得到县")
    @GetMapping("selectDistinct")
    public SysResult selectDistinct(String city) {
        List<SmallScaleStation> smallScaleStationList = this.qxxxzService.selectDistinct(city);
        return SysResult.success(smallScaleStationList);
    }

    @ApiOperation("区域自动站-查询得到列表,根据stationId,stationName,city,county")
    @GetMapping("selectQuery")
    public SysResult selectQuery(SmallScaleStation smallScaleStation) {
        List<SmallScaleStation> smallScaleStations = this.qxxxzService.selectQuery(smallScaleStation);
        return SysResult.success(smallScaleStations);
    }

    @ApiIgnore
    @RequestMapping(value = "querySmallScaleStation", method = RequestMethod.GET)
    @ApiOperation("区域自动站-根据stationId,stationName,city,county进行模糊查询")
    public SysResult querySmallScaleStation(String stationId, String stationName, String city, String county) {
        List<SmallScaleStation> smallScaleStations = this.qxxxzService.querySmallScaleStation(stationId, stationName, city, county);
        return SysResult.success(smallScaleStations);
    }

    @ApiOperation("区域自动站-根据Stationid查询单条记录")
    @GetMapping("selectByStationId")
    public SysResult selectByStationId(String stationId) {
        SmallScaleStation smallScaleStation = new SmallScaleStation();
        smallScaleStation.setStationid(stationId);
        List<SmallScaleStation> smallScaleStations = this.qxxxzService.selectById(smallScaleStation);
        return SysResult.success(smallScaleStations);
    }

    @ApiOperation("区域自动站-保存")
    @PostMapping("addSmallScaleStation")
    public SysResult addSmallScaleStation(@RequestBody SmallScaleStation smallScaleStation) {
        Integer integer = this.qxxxzService.addSmallScaleStation(smallScaleStation);
        if (integer > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }

    @ApiOperation("区域自动站-修改")
    @PostMapping("updateSmallScaleStation")
    public SysResult updateSmallScaleStation(@RequestBody SmallScaleStation smallScaleStation) {
        Integer integer = this.qxxxzService.updateSmallScaleStation(smallScaleStation);
        if (integer > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }

    @ApiOperation("区域自动站-删除")
    @PostMapping("deleteSmallScaleStation")
    public SysResult deleteSmallScaleStation(String stationId) {
        Integer integer = this.qxxxzService.deleteSmallScaleStation(stationId);
        if (integer > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }

    /**
     * 特殊服务站
     *
     * @return
     */
    @ApiOperation("特殊服务站-得到服务站类型")
    @GetMapping("queryFlagFromSpecialSrvStation")
    public SysResult queryFlagFromSpecialSrvStation() {
        List<SpecialSrvStation> distinct_flag = this.qxxxzService.querySpecialSrvStation("distinct flag", null, null);
        return SysResult.success(distinct_flag);
    }

    @ApiIgnore
    @ApiOperation("select distinct name")
    @GetMapping("queryNameFromCountyPoint")
    public SysResult queryNameFromCountryPoint() {
        List<CountyPoint> distinct_name = this.qxxxzService.queryDistinctCountyPoint("distinct name");
        return SysResult.success(distinct_name);
    }

    @ApiIgnore
    @ApiOperation("select distinct city not like city")
    @GetMapping("queryCityFromSpecialSrvStation")
    public SysResult queryCityFromSpecialSrvStation(String city) {
        List<SpecialSrvStation> specialSrvStations = this.qxxxzService.querySpecialSrvStation("distinct city", "not", city);
        return SysResult.success(specialSrvStations);
    }

    @ApiIgnore
    @ApiOperation("特殊服务站-得到所有服务站")
    @GetMapping("queryAllSpecialSrvStation")
    public SysResult queryAllSpecialSrvStation() {
        List<SpecialSrvStation> specialSrvStations = this.qxxxzService.queryAllSpecialSrvStation();
        return SysResult.success(specialSrvStations);
    }

    @ApiIgnore
    @ApiOperation("select distinct city  like city")
    @GetMapping("queryCityFromSpecialSrvStation2")
    public SysResult queryCityFromSpecialSrvStation2(String city) {
        List<SpecialSrvStation> distinct_city = this.qxxxzService.querySpecialSrvStation("distinct city", null, city);
        return SysResult.success(distinct_city);
    }

    @ApiIgnore
    @ApiOperation("select distinct county")
    @GetMapping("queryDistinctCounty")
    public SysResult queryDistinctCounty(String city) {
        List<SpecialSrvStation> distinct_county = this.qxxxzService.querySpecialSrvStation("distinct county", null, city);
        return SysResult.success(distinct_county);
    }

    @ApiOperation("特殊服务站-模糊查询-根据类型、市、县、站点编号、站点名称")
    @GetMapping("queryLikeSpecialSrvStation")
    public SysResult queryLikeSpecialSrvStation(SpecialSrvStation specialSrvStation) {
        List<SpecialSrvStation> specialSrvStations = this.qxxxzService.queryLikeSpecialSrvStation(specialSrvStation);
        return SysResult.success(specialSrvStations);
    }

    @ApiOperation("特殊服务站-根据Stationid和flag查询单条记录")
    @GetMapping("selectSpecialSrvByStationId")
    public SysResult selectSpecialSrvByStationId(String stationId,String flag) {
        SpecialSrvStation specialSrvStation = new SpecialSrvStation();
        specialSrvStation.setStationid(stationId);
        specialSrvStation.setFlag(flag);
        List<SpecialSrvStation> smallScaleStations = this.qxxxzService.queryLikeSpecialSrvStation(specialSrvStation);
        return SysResult.success(smallScaleStations);
    }


    @ApiOperation("特殊服务站-保存")
    @PostMapping("saveSpecialSrvStation")
    public SysResult saveSpecialSrvStation(@RequestBody SpecialSrvStation specialSrvStation) {
        List<SpecialSrvStation> specialSrvStations = this.qxxxzService.queryStationIdFromSpecialSrvStation(specialSrvStation.getStationid(), specialSrvStation.getFlag());
        if (specialSrvStations.size() > 0) {
            return SysResult.fail("已存在相同站点");
        } else {
            Integer integer = this.qxxxzService.saveSpecialSrvStation(specialSrvStation);
            if (integer > 0) {
                return SysResult.success();
            } else {
                return SysResult.fail();
            }
        }
    }

    @ApiOperation("特殊服务站-更新")
    @PostMapping("updateSpecialSrvStation")
    public SysResult updateSpecialSrvStation(@RequestBody SpecialSrvStation specialSrvStation) {
        Integer integer = this.qxxxzService.updateSpecialSrvStation(specialSrvStation);
        if (integer > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }


    @ApiOperation("特殊服务站-删除")
    @GetMapping("deleteSpecialSrvStation")
    public SysResult deleteSpecialSrvStation(String stationId) {
        Integer integer = this.qxxxzService.deleteSpecialSrvStation(stationId);
        if (integer > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }

    @ApiIgnore
    @ApiOperation("select from township_station like city ")
    @GetMapping("queryTownShipStationLikeCity")
    public SysResult queryTownShipStationLikeCity(String city) {
        List<TownshipStation> townshipStations = this.qxxxzService.queryTownShipStationLikeCity(city);
        return SysResult.success(townshipStations);
    }

    @ApiIgnore
    @ApiOperation("insert ")
    @PostMapping("saveTownShipStation")
    public SysResult saveTownShipStation(@RequestBody TownshipStation townshipStation) {
        List<TownshipStation> townshipStations = this.qxxxzService.selectStationId(townshipStation.getStationid());
        if (townshipStations.size() > 0) {
            return SysResult.fail("存在相同");
        } else {
            Integer integer = this.qxxxzService.saveTownShipStation(townshipStation);
            return SysResult.success(integer);
        }
    }

    @ApiIgnore
    @ApiOperation("update ")
    @PostMapping("updateTownShipStation")
    public SysResult updateTownShipStation(@RequestBody TownshipStation townshipStation) {
        List<TownshipStation> townshipStations = this.qxxxzService.selectStationId(townshipStation.getStationid());
        if (townshipStations.size() > 0) {
            Integer integer = this.qxxxzService.saveTownShipStation(townshipStation);
            return SysResult.success(integer);
        } else {
            return SysResult.fail("不存在该站点");
        }
    }

    @ApiIgnore
    @ApiOperation("delete ")
    @GetMapping("deleteTownShipStation")
    public SysResult deleteTownShipStation(String stationId) {
        Integer integer = this.qxxxzService.deleteTownShipStation(stationId);
        return SysResult.success(integer);
    }

    @ApiIgnore
    @ApiOperation("select distinct type from ybzz_forecaststation")
    @GetMapping("selectDistinctTypeFromYbzzForeaStation")
    public SysResult selectDistinctTypeFromYbzzForeaStation() {
        List<YbzzForecaststation> ybzzForecaststations = this.qxxxzService.selectDistinct("distinct type", null, null);
        return SysResult.success(ybzzForecaststations);
    }

    @ApiIgnore
    @ApiOperation("select from ybzz_forecaststation")
    @GetMapping("selectAllYbzzForecStation")
    public SysResult selectAllYbzzForecStation() {
        List<YbzzForecaststation> ybzzForecaststations = this.qxxxzService.selectAllYbzzForecStation();
        return SysResult.success(ybzzForecaststations);
    }

    @ApiIgnore
    @ApiOperation("insert")
    @PostMapping("saveYbzzForecStation")
    public SysResult saveYbzzForecStation(@RequestBody YbzzForecaststation ybzzForecaststation) {
        List<YbzzForecaststation> ybzzForecaststations = this.qxxxzService.selectByStationIdYbzzForecStation(ybzzForecaststation.getStationid());
        if (ybzzForecaststations.size() > 0) {
            return SysResult.fail("存在相同值");
        } else {
            Integer integer = this.qxxxzService.saveYbzzForecaststation(ybzzForecaststation);
            return SysResult.success(integer);
        }
    }

    @ApiIgnore
    @ApiOperation("update")
    @PostMapping("updateYbzzForecStation")
    public SysResult updateYbzzForecStation(@RequestBody YbzzForecaststation ybzzForecaststation) {
        List<YbzzForecaststation> ybzzForecaststations = this.qxxxzService.selectByStationIdYbzzForecStation(ybzzForecaststation.getStationid());
        if (ybzzForecaststations.size() > 0) {
            Integer integer = this.qxxxzService.updateYbzzForecaststation(ybzzForecaststation);
            return SysResult.success(integer);
        } else {
            return SysResult.fail("不存在此条数据");
        }
    }

    @ApiIgnore
    @ApiOperation("delete")
    @GetMapping("deleteYbzzForecStation")
    public SysResult deleteYbzzForecStation(String stationId) {
        List<YbzzForecaststation> ybzzForecaststations = this.qxxxzService.selectByStationIdYbzzForecStation(stationId);
        if (ybzzForecaststations.size() > 0) {
            Integer integer = this.qxxxzService.deleteYbzzForecaststation(stationId);
            return SysResult.success(integer);
        } else {
            return SysResult.fail("不存在此条数据");
        }
    }
}
